package com.jds.test.websocket;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

/**
 * Created by sunyuming on 18/9/14.
 */
public class WebSocketFrameEncoder extends MessageToMessageEncoder<String> {

    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        // MessageToMessageEncoder 会自动释放msg，if msg instanceof ReferenceCounted
     //   out.add(new TextWebSocketFrame(msg).retain());   // 往下一个outHandler传递，不用＋1年龄
        out.add(new TextWebSocketFrame(msg));
    }
}